package com.itic.demo.modelfiles.service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itic.appbase.framework.common.basevo.User;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.constants.IticConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.appbase.framework.utils.IdGen;
import com.itic.demo.modelfiles.persistence.dao.ModelFilesDao;
import com.itic.demo.modelfiles.persistence.model.ModelFiles;
import com.itic.demo.modelfiles.persistence.model.ModelFilesExample;


@Service
@Transactional
public class ModelFilesService extends CrudService<ModelFilesDao,ModelFiles,ModelFilesExample> {
    @Autowired
    private ModelFilesDao modelFilesDao;

    //批量导入业务
	public String imp(HttpServletRequest request,List<ModelFiles> dataList) {
		if(dataList.size()>0){
			Date date = new Date();
			User user = (User)request.getSession().getAttribute(IticConst.PS_SESSION_USERINFO_KEY);
			
			for(ModelFiles temp:dataList){
				temp.setId(IdGen.uuid());
				temp.setCreateTime(date);
				temp.setUpdateTime(date);
				temp.setIsEffective(DBConst.TRUE);
				
				temp.setOrgCode(user.getOrg());
				temp.setCreateUser(user.getId());
				modelFilesDao.insert(temp);
			}
		}
		return "success";
	}
    public List<ModelFiles> getFiles(String ids){
        String[] arrayIds = ids.split(",");
        //System.out.println("*******************************************");
        //for (String string : arrayIds) {
		//	System.out.println("arrayIds ==="+string);
		//}
        System.out.println("*******************************************");
        ModelFilesExample example = new ModelFilesExample();
        example.createCriteria().andIdIn(Arrays.asList(arrayIds)).andIsEffectiveEqualTo(DBConst.TRUE);
        return modelFilesDao.selectByExample(example);
      }
    public ModelFiles getFile(String id){
    	return modelFilesDao.selectByPrimaryKey(id);
    }


}